/**
 * \file PLog.h
 * \brief PEPCI-specific CLog class.
 * \author Wouter Caarls <w.caarls@tnw.tudelft.nl> 
 *
 * \verbatim
 * Copyright (c) 2005 Wouter Caarls, Delft University of Technology
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * \endverbatim
 */

#ifndef __PLOG_H_INCLUDED
#define __PLOG_H_INCLUDED

#include <log.hpp>

#define LOG(s, x) if ((s).IsEnabled()) (s)() << x

class PLog
{
  public:
    CLogStream err,
               warning,
               notice, 
               reduce,
               residualize,
               stratego,
               info,
               symbols,
               parse,
               debug,
               crawl;

  public:
    PLog(const char *name="plog", const char *file=NULL)
    {
      Construct(name, file);
    }

    void Reconstruct(const char *name="plog", const char *file=NULL)
    {
      Construct(name, file);
    }        

  private:
    void Construct(const char *name, const char *file)
    {
      int s;
      char *_file = _file;

      /* Attach our streams */
      if (!name || (s = logGetFirstGroupStream(name)) < 0)
      {
        /* New streams */
        logAddNamedGroup(name);

	if (!file) _file = "stderr";

        err.SetStream(logAddStream("\x1B[31m\x1B[1mERR\x1B[0m %s(%l) %f: ", _file));
        warning.SetStream(logAddStream("\x1B[33m\x1B[1mWRN\x1B[0m %s(%l) %f: ", _file));

	if (!file) _file = "stdout";

        notice.SetStream(logAddStream("\x1B[34m\x1B[1mNTC\x1B[0m %f: ", _file));
        reduce.SetStream(logAddStream("\x1B[32m\x1B[1mRED\x1B[0m %f: ", _file));
        residualize.SetStream(logAddStream("\x1B[32mRES\x1B[0m %f: ", _file));
        stratego.SetStream(logAddStream("\x1B[36m\x1B[1mSTR\x1B[0m %f: ", _file));
        info.SetStream(logAddStream("\x1B[37m\x1B[1mINF\x1B[0m %f: ", _file));
        symbols.SetStream(logAddStream("\x1B[36mSYM\x1B[0m %f: ", _file));
        parse.SetStream(logAddStream("\x1B[32m\x1B[1mPAR\x1B[0m %f: ", _file));
        debug.SetStream(logAddStream("\x1B[1mDBG\x1B[0m %f: ", _file));
        crawl.SetStream(logAddStream("CRL %f: ", _file));
      }
      else
      {
        /* Old streams */
        err.SetStream(s);
        warning.SetStream(s = logGetNextGroupStream(s));
        notice.SetStream(s = logGetNextGroupStream(s));
        reduce.SetStream(s = logGetNextGroupStream(s));
        residualize.SetStream(s = logGetNextGroupStream(s));
        stratego.SetStream(s = logGetNextGroupStream(s));
        info.SetStream(s = logGetNextGroupStream(s));
        symbols.SetStream(s = logGetNextGroupStream(s));
        parse.SetStream(s = logGetNextGroupStream(s));
        debug.SetStream(s = logGetNextGroupStream(s));
        crawl.SetStream(s = logGetNextGroupStream(s));
      }      
    }
};

#endif /* __PLOG_H_INCLUDED */
